package com.bangcommunity.bbframe.common.utils.id;

import com.bangcommunity.bbframe.common.utils.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 *
 * @author tanghc
 * @date 17/1/22
 */
public class DangDangIdFactory {
    static Logger logger = LoggerFactory.getLogger(DangDangIdFactory.class);
    private static final Map<String, DangDangIdGenerator> idGenerators = new ConcurrentHashMap<>();

    private DangDangIdFactory() {
    }

    private static class DangDangIdFactoryHolder {
        private static DangDangIdFactory instance = new DangDangIdFactory();
    }

    public static DangDangIdFactory getInstance() {
        return DangDangIdFactoryHolder.instance;
    }

    public DangDangIdGenerator getIdGenerator(String key) {
        if (StringUtils.isNotBlank(key)) {
            DangDangIdGenerator dangDangIdGenerator = idGenerators.get(key);
            if (null == dangDangIdGenerator) {
                dangDangIdGenerator = new DangDangIdGenerator();
                idGenerators.put(key, dangDangIdGenerator);
            }
            return dangDangIdGenerator;
        }
        return null;
    }

}